﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using UnliQ.Service.Contracts;

namespace UnliQ.Web
{
    public static class InitValuesConfig
    {

        private static IQueueService _service = null;
        private static IUserService _userservice = null;

        public static void SeedUser(IUserService service)
        {
            _userservice= service;
            var userList = new List<UserDTO>()
            {
                new UserDTO
                {
                    UserId = 1,
                    Username = "Leo Galang"
                },
                new UserDTO
                {
                    UserId = 2,
                    Username = "Fab Onan"
                },
                new UserDTO
                {
                    UserId = 3,
                    Username = "Joseph Villar"
                },
                new UserDTO
                {
                    UserId = 4,
                    Username = "Jerome Corpuz"
                }
            };
            _userservice.AddInitValues(userList);
        }

        public static void Seed(IQueueService service)
        {
            _service = service;
            List<string> eventNames = new List<string>();
            eventNames.Add("Xray");
            eventNames.Add("APE");
            eventNames.Add("Doctor Consulation");
            eventNames.Add("ITR");
            eventNames.Add("Payslip");
            eventNames.Add("Interview");


            var recurring = new List<RecurringDTO>()
            {
                new RecurringDTO
                {
                    Id = 1,
                    Name = "",
                    Description = "",
                    Active = true
                },
                new RecurringDTO
                {
                    Id = 0,
                    Name = "Any day of the week",
                    Description = "Any day of the week description",
                    Active = true
                }
            };

            var eventRecurring = new List<EventRecurringDTO>()
            {
                new EventRecurringDTO()
                {
                    Id = 1,
                    RecurringId = 1,
                    Value = "1,2,3,4,5",
                    RecurringDTO = recurring.Where(w => w.Id == 1).FirstOrDefault()
                }
            };

            var eventDates = new List<EventDateDTO>();
            var eventDateSequence = new List<EventDateSequenceDTO>();

            for (int i = 1; i <= 6; i++)
            {
                eventDates.Add(new EventDateDTO
                {
                    Id = i,
                    EventId = i,
                    EventRecurringId = 1,                    
                    SubscribeStartDate = new DateTime(2013, 4, 12),
                    SubscribeEndDate = new DateTime(2013, 4, 13),
                    EventStartDate = new DateTime(2013, 4, 12),
                    EventEndDate = new DateTime(2013, 4, 13),
                    EventRecurringDTO = eventRecurring.Where(w => w.Id == 1).FirstOrDefault()
                });

                eventDateSequence.Add(new EventDateSequenceDTO 
                { 
                    Id = i,
                    EventDateId = i,
                    SubscribeStartDate = new DateTime(2013, 4, 12),
                    SubscribeEndDate = new DateTime(2013, 4, 13),
                    EventStartDate = new DateTime(2013, 4, 12),
                    EventEndDate = new DateTime(2013, 4, 13)
                });
            }

            

            var events = new List<EventDTO>();
            var eventTrigger = new List<EventTriggerDTO>();

            for (int i = 1; i <= 6; i++)
            {                
                eventTrigger.Add(new EventTriggerDTO 
                {
                    Id = i,
                    UserId = 1,
                    EventId = i,
                    Active = true
                });

                events.Add(new EventDTO
                {
                    Id = i,
                    Name = eventNames[i-1].ToString(),//"X-Ray " + i.ToString(),
                    Description = "Event Description " + i.ToString(),
                    Room = "Room " + i.ToString(),
                    PersonInCharge = i,
                    Private = false,                   
                    CreatedDate = new DateTime(2013, i, i + 1),
                    Active = true,
                    EventDateDTO = eventDates.Where(w => w.EventId == i).FirstOrDefault(),
                    EventTriggerDTO = eventTrigger.Where(w => w.EventId == i).FirstOrDefault()
                });
            }

            _service.AddInitValues(events, eventDates, recurring, eventRecurring, eventDateSequence, eventTrigger);
        }

    }
}